#include "../logs/maglog.h"
#include <fstream>
#include <iostream>

void testDiskFull() {
    LOGI("开始磁盘写满测试");

    // 模拟磁盘写满
    std::ofstream ofs("/home/bitlog/test/fill_disk.txt", std::ios::binary);
    const size_t bufferSize = 1024 * 1024; // 1 MB
    char buffer[bufferSize] = {0};

    try {
        while (true) {
            ofs.write(buffer, bufferSize);
            if (ofs.fail()) {
                LOGE("磁盘已满或写入失败！");
                break;
            }
        }
    } catch (const std::exception &e) {
        LOGE("磁盘写满测试异常: %s", e.what());
    }

    LOGI("磁盘写满测试结束");
}

void testDiskReadOnly() {
    LOGI("开始磁盘只读测试");

    // 将目录挂载为只读
    std::string command = "sudo mount -o remount,ro /home/bitlog/log";
    if (system(command.c_str()) != 0) {
        LOGE("无法将磁盘目录挂载为只读");
    }

    LOGI("磁盘只读测试结束");
}

int main() {
    // 执行磁盘写满测试
    testDiskFull();

    // 执行磁盘只读测试
    testDiskReadOnly();

    return 0;
}
